﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Frame.Lib.Core.Base;
using Frame.Lib.Utilities;
using Frame.Lib.Data;


namespace Jzy.DAL.Project
{
    public class TaskOverseeDAL:BaseDAL
    {
        private string _taskID;
        public TaskOverseeDAL(string taskID)
        {
            _taskID=taskID;
        }
        public static DataTable GetLastRemark(List<int> prjIDs)
        {
            string ids = ConvertUtil.ConvertToDbStr(prjIDs);
            string sql = "select a.*, b.PrjID from " + OTableName.PrjTaskOversee + " a inner join " + OTableName.PrjTask + " b on a.TaskID = b.ID where a.ID in " +
                         "(select max(c.id) from " + OTableName.PrjTaskOversee + " c inner join " + OTableName.PrjTask + " d on c.TaskID = d.ID inner join " + OTableName.Project + " e on d.PrjID = e.ID " +
                         "where e.ID in (" + ids + ") Group by e.ID)";

            DataTable dt = DBHelper.Instance().Query(sql);
            return dt;
        }

        public DataTable GetDataTable()
        {
            string sql = "select *,(select Name from " + OTableName.PrjTask + " where ID = TaskID) as TaskName from " + OTableName.PrjTaskOversee + " where TaskID = @p0 order by InputTime desc";
            DataTable dt = dbOper.Query(sql, _taskID);
            return dt;
        }

        public static System.Data.DataTable GetDataTableByPrjID(string prjID)
        {
            string sql = "select *,(select Name from " + OTableName.PrjTask + " where ID = TaskID) as TaskName from " + OTableName.PrjTaskOversee +
                         " where TaskID in (select ID from " + OTableName.PrjTask + " where PrjID = @p0) order by TaskID,InputTime desc";
            DataTable dt = DBHelper.Instance().Query(sql, prjID);
            return dt;
        }
    }
}
